package com.xjc.infra.util;

import com.xjc.infra.entity.BaseErrorCode;
import com.xjc.infra.entity.ExecuteState;
import com.xjc.infra.entity.service.TransactionStatus;

/**
*  公用工具类
* @author    [liangcz]
* @version   [1.0, 2016-07-12]
*/
public class InfraUtil {
	
	
	/**
	* 
	* 内部状态对象转换成 外部状态对象
	* 内部状态对象转换成 外部状态对象 
	* @param  ExecuteState state     
	* @return  TransactionStatus staus
	* @exception 
	* @see         
	*/
	public static TransactionStatus transferStatusObj(ExecuteState state){
		TransactionStatus ts = new TransactionStatus();
		if(null == state){
			ts.setErrorCode(BaseErrorCode.BASE_ERROR);
			ts.setReplyText("交易失败");
			return ts;
		}
		ts.setSuccess(state.isSuccess());
		ts.setReplyText(state.getMessage());
		if(!state.isSuccess())
		{
			ts.setErrorCode(state.getErrorCode());
		}
		return ts;
	}
	
	/**
	* 
	* 外部状态对象转换成 内部状态对象
	* 外部状态对象转换成 内部状态对象
	* @param  TransactionStatus staus     
	* @return  ExecuteState state
	* @exception 
	* @see         
	*/
	public static ExecuteState transferStatusObj(TransactionStatus ts){
		ExecuteState state = new ExecuteState();
		if(null == ts){
			state.setErrorCode(BaseErrorCode.BASE_ERROR);
			state.setMessage("交易失败");
			return state;
		}
		
		state.setSuccess(ts.isSuccess());
		state.setMessage(ts.getReplyText());
		if(!state.isSuccess())
		{
			state.setErrorCode(ts.getErrorCode());
		}
		return state;
	}
	
	
	
	
}
